home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / picture / animate.c next >
Text File  |  1993-09-23  |  2KB  |  78 lines

  1. //    Copyright 1993 Ralph Gonzalez
  2.  
  3. /*
  4. *    FILE:        animate.c
  5. *    AUTHOR:        R. Gonzalez
  6. *    CREATED:    November 8, 1990
  7. *
  8. *    defines methods for animated nested segment
  9. */
  10.  
  11. # include    "animate.h"
  12. # include    "error.h"
  13. # include    <stdlib.h>
  14.  
  15. extern Error    *gerror;
  16.  
  17. /******************************************************************
  18. *    initialize.
  19. *    Be sure to allocate and initialize an element of the array
  20. *    animation[] for each segment.  This element indicates how
  21. *    the respective segment is transformed when the nested segment
  22. *    is animated.  If any of the segments are themselves animated
  23. *    segments, then you must call:
  24. *        log_animated_segment(segment[i]);
  25. ******************************************************************/
  26. Animated_Segment::Animated_Segment(void)
  27. {
  28.     int        i;
  29.     
  30.     for (i=0 ; i<MAX_SEGMENTS ; i++)
  31.         animation[i] = NULL;
  32.     
  33.     num_animated_segments = 0;
  34. }
  35.  
  36. /******************************************************************
  37. *    animate - no need to override
  38. ******************************************************************/
  39. void    Animated_Segment::animate(void)
  40. {
  41.     int        i;
  42.     
  43.     for (i=0 ; i<num_animated_segments ; i++)
  44.         animated_segment_ptr[i]->animate();
  45.     
  46.     for (i=0 ; i<num_segments ; i++)
  47.     {
  48.         if (animation[i] == NULL)
  49.             gerror->report("Missing animation for this segment");
  50.         else
  51.             segment[i]->move(animation[i]);
  52.     }
  53. }
  54.  
  55. /******************************************************************
  56. *    Log a pointer to an animated segment in the array
  57. *    animated_segment_ptr[] and increment num_animated_segments.
  58. ******************************************************************/
  59. void    Animated_Segment::log_animated_segment(Segment* seg)
  60. {
  61.     animated_segment_ptr[num_animated_segments++] =
  62.         (Animated_Segment*) seg;
  63. }
  64.  
  65. /******************************************************************
  66. *    destroy - no need to override.
  67. ******************************************************************/
  68. Animated_Segment::~Animated_Segment(void)
  69. {
  70.     int        i;
  71.     
  72.     for (i=0 ; i<num_segments ; i++)
  73.         if (animation[i] != NULL)
  74.             delete animation[i];
  75. }
  76.  
  77.  
  78.